#!/usr/bin/python3
# -*- coding:utf-8 -*-
#python version: 3.6.7

import time

def get_url_dict(mtwm_curl):
    #用一个字典来保存所有的url
    url_dict = {}
    #多点已完成订单的url
    url_dict['dmall_order'] = (
        'https://fulproduce-partner.dmall.com/produceOrderList/list'
    )
    #多点缺货订单的url
    url_dict['dmall_absence'] = (
        'https://manlack-partner.dmall.com/lack/waitingReplyList'
    )
    #多点地推报表的url
    url_dict['dmall_achievement'] = (
        'https://marketplus-partner.dmall.com/'
        'partner/store/report/achievement/report'
    )
    #海博订单列表查询的url
    url_dict['hiboos_order'] = (
        'https://zt.hiboos.com/wmsOrder/queryOrderByPage'
    )
    #海博取消订单列表的url
    url_dict['hiboos_cancel_list'] = (
        'https://zt.hiboos.com/wmsOrder/queryOrderByPage'
    )
    #海博订单详情的url
    url_dict['hiboos_absence'] = (
        'https://zt.hiboos.com/order/getOrderDetail'
    )
    #京东日报的url
    url_dict['jddj'] = (
        'https://store.jddj.com/client'
        '?appName=scpc'
        '&functionId=%2FgateWay%2FnewHome%2F'
        'getTodayFinishOrderNumAndMoney'
        '&body=%7B%7D'
    )
    #美团日报的url
    in_s = mtwm_curl.index('\'') + 1
    in_e = mtwm_curl.index('\'', in_s)
    url_dict['mtwm'] = mtwm_curl[in_s: in_e]
    #饿了么日报的url
    url_dict['ele'] = ('https://ebai.ele.me/'
    'api/dashboard/bussiness/realtime?roleType=1')

    return url_dict

def get_post_param(dmall_curl):
    #取出多点的门店号
    in_s = dmall_curl.index('storeIds=') + 9
    in_e = dmall_curl.index('&', in_s)
    storeid = dmall_curl[in_s: in_e]
    #用一个字典来保存所有的data
    data_dict = {}
    #多点已完成订单的post data
    data_dict['dmall_order'] = {
            'storeIds' : storeid,
            'completeTime' : time.strftime('%Y-%m-%d', time.localtime()),
            'orderStatus' : '64,65',
            'pageSize' : '2048',
            'pageNo' : '1'
    }
    #多点缺货订单的post data
    data_dict['dmall_absence'] = {
        'reportStartTime' : time.strftime('%Y-%m-%d', time.localtime()),
        'reportEndTime' : time.strftime('%Y-%m-%d', time.localtime()),
        'venderId' : '60',
        'rows' : '30',
        'page' : '1'
    }
    #多点地推报表的post data
    data_dict['dmall_achievement'] = {
        'metricList': '11',
        'storeId': storeid,
        'startDate': time.strftime('%Y%m01', time.localtime()),
        'endDate': time.strftime('%Y%m%d', time.localtime()),
        'current': '1',
        'size': '10'
    }
    #海博订单列表查询的post data
    data_dict['hiboos_order'] = {
        'body' : (
            '{"startTime":"' +
            time.strftime('%Y-%m-%d', time.localtime()) +
            '00:00:00",' +
            '"endTime":"' +
            time.strftime('%Y-%m-%d', time.localtime()) +
            ' 23:59:59",' +
            '"timeBegin":"' +
            time.strftime('%Y-%m-%d', time.localtime()) +
            ' 00:00:00",' +
            '"timeEnd":"' +
            time.strftime('%Y-%m-%d', time.localtime()) +
            ' 23:59:59",' +
            '"selectTimeType":"4",' +
            '"stationNo":"",' +
            '"statusSet":[]}'
        ),
        'page' : '{"pageNo":0,"pageSize":100}'
    }
    #海博取消订单列表的post data
    data_dict['hiboos_cancel_list'] = {
        'body' : data_dict['hiboos_order']['body'].replace(
            '[]','["70"]'
        ),
        'page' : '{"pageNo":1,"pageSize":100}'
    }
    #海博订单详情的post data
    data_dict['hiboos_absence'] = {
        'body' : '{"orderId":"中台订单编号"}'
    }

    return data_dict

def curl2header_dict(str_curl):
    header_dict = {}
    #从curl文本中取出headers
    in_s = str_curl.index('\n') + 7
    in_e = str_curl.lower().index('\'cookie') - 9
    text_headers = str_curl[in_s: in_e]
    #把取出的headers转成python字典格式
    if '  -h ' in text_headers:
        temp_headers = text_headers.split('\' \\\n  -h \'')
    else:
        temp_headers = text_headers.split('\' \\\n  -H \'')
    temp_headers = [j.split(': ') for j in temp_headers]
    dict_headers = {j[0]:j[1] for j in temp_headers}
    return dict_headers

def curl2cookie_dict(str_curl):
    in_s = str_curl.lower().index('\'cookie')
    in_s = str_curl.index(' ', in_s)
    in_e = str_curl.index('\\\n', in_s)
    str_curl = str_curl[in_s: in_e].replace(' ', '')
    #把取出的cookies转成python字典格式
    temp_cookies = str_curl.split(';')
    temp_cookies = [j.split('=') for j in temp_cookies]
    dict_cookies = {j[0]:j[1] for j in temp_cookies}
    return dict_cookies
